package gold.digger;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC1006 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int clumsy(int n) {
            int lastOpNum = n;
            char curOp = '?';
            while (--n > 0) {
                curOp = getNextOperator(curOp);
                switch (curOp) {
                    case '*':
                        lastOpNum *= n;
                        break;
                    case '/':
                        lastOpNum /= n;
                        break;
                    case '+':
                        lastOpNum += n;
                        break;
                    case '-':
                        int curSubtractNum = n;
                        if (n >= 3) {
                            curSubtractNum = n * (n - 1) / (n - 2);
                            n -= 2;
                            curOp = '/';
                        } else if (n >= 2) {
                            curSubtractNum = n * (n - 1);
                            n -= 1;
                            curOp = '*';
                        } else curSubtractNum = n;
                        lastOpNum -= curSubtractNum;
                        break;
                }
            }

            return lastOpNum;
        }

        public Character getNextOperator(char cur) {
            switch (cur) {
                case '*':
                    return '/';
                case '/':
                    return '+';
                case '+':
                    return '-';
                case '-':
                    return '*';
            }

            return '*';
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.clumsy(11));
    }

    public static void main(String[] args) throws Exception {
        LC1006 an = new LC1006();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
